Ext.data.DWRProxy = function(dwrCall, dwrArgs){
  Ext.data.DWRProxy.superclass.constructor.call(this);
  this.dwrCall = dwrCall;
  //this.args = args;
  //this.pagingAndSort = (pagingAndSort!=undefined ? pagingAndSort : true);
  this.dwrArgs = dwrArgs;
};

Ext.extend(Ext.data.DWRProxy, Ext.data.DataProxy, {
  load : function(params, reader, callback, scope, arg) {
      if(this.fireEvent("beforeload", this, params) !== false) {
      //var sort;
     // if(params.sort && params.dir) sort = params.sort + ' ' + params.dir;
      //else sort = '';
      var delegate = this.loadResponse.createDelegate(this, [reader, callback, scope, arg], 1);
      var callParams = new Array();
      //if(arg.arg) {
       // callParams = arg.arg.slice();
			//}
			
		//if(this.pagingAndSort) {
      	//callParams.push(params.start);
        //callParams.push(params.limit);
      	//callParams.push(sort);
		//}
	  //callParams.push(arg.params);
	  if(this.dwrArgs){
	  	for(var i=0; i< this.dwrArgs.length; i++){
	  		callParams.push(this.dwrArgs[i]);
	  	}
	  }
      callParams.push(delegate);
      this.dwrCall.apply(this, callParams);
    } else {
      callback.call(scope || this, null, arg, false);
    }
  },

  loadResponse : function(dwrResult, reader, callback, scope, arg) {
    var result;
    try {
      result = reader.read(dwrResult);
    } catch(e) {
      this.fireEvent("loadexception", this, null, dwrResult, e);
      callback.call(scope, null, arg, false);
      return;
    }
    callback.call(scope, result, arg, true);
  }
});

Ext.data.BeanListReader = function(meta, recordType){

    Ext.data.BeanListReader.superclass.constructor.call(this, meta, recordType);
};

Ext.extend(Ext.data.BeanListReader, Ext.data.DataReader, {
	read : function(response){
		var recordType = this.recordType, fields = recordType.prototype.fields; 
		var records = []; 
		var sid = this.meta ? this.meta.id : null;
		var root = response; 
		for(var i = 0; i < root.length; i++){ 
			var obj = root[i]; 
			var values = {}; 
			var id = obj[sid]; 

			for(var j = 0, jlen = fields.length; j < jlen; j++){ 
				var f = fields.items[j]; 
				var k = f.mapping !== undefined && f.mapping !== null ? f.mapping : f.name;
				var v = obj[k] !== undefined ? obj[k] : f.defaultValue;
				
				if(v==null || v=='null') v=f.defaultValue; 
				v = f.convert(v); 
				values[f.name] = v; 
			} 
			var record = new recordType(values, id); 
			records[records.length] = record; 
		} 
		return { 
			records : records, 
			totalRecords : records.length 
		}; 
	} 
  }
);